package jee.boot.common.properties;

import org.springframework.boot.context.properties.ConfigurationProperties;

import java.util.ArrayList;
import java.util.List;

/**
 * 访问请求的白名单
 * 
 * @author zhilei.wang
 *
 */
@ConfigurationProperties(prefix = "permit")
public class PermitUrlProperties {

	/**
	 * 监控中心和swagger需要访问的url
	 */
	// @formatter:off
	private static final String[] ENDPOINTS = 
		{ 
			"/**/actuator/health", 
			"/**/actuator/env", 
			"/**/actuator/metrics/**", 
			"/**/actuator/trace", 
			"/**/actuator/dump", 
			"/**/actuator/jolokia",
			"/**/actuator/info", 
			"/**/actuator/logfile", 
			"/**/actuator/refresh", 
			"/**/actuator/flyway", 
			"/**/actuator/liquibase", 
			"/**/actuator/heapdump", 
			"/**/actuator/loggers",
			"/**/actuator/auditevents", 
			"/**/actuator/env/PID", 
			"/**/actuator/jolokia/**", 
			"/**/actuator/archaius/**", 
			"/**/actuator/beans/**", 
			"/**/actuator/httptrace", 
			"/**/v2/api-docs/**",
			"/**/swagger-ui.html", 
			"/**/swagger-resources/**", 
			"/**/webjars/**", 
			"/jasperreports/**", //测试的
			"/**/jasperreports/**",
			"/**/druid/**" ,
			"/**/static/**" //静态文件
		};
	// @formatter:on
	private String[] httpUrls;
	private String[] oauthUrls;

	public String[] getHttpUrls() {
		if (httpUrls == null || httpUrls.length == 0) {
			return ENDPOINTS;
		}

		List<String> list = new ArrayList<>();
		for (String url : ENDPOINTS) {
			list.add(url);
		}
		for (String url : httpUrls) {
			list.add(url);
		}

		return list.toArray(new String[list.size()]);
	}

	public void setHttpUrls(String[] http_urls) {
		this.httpUrls = http_urls;
	}

	public String[] getOauthUrls() {
		if (oauthUrls == null || oauthUrls.length == 0) {
			return ENDPOINTS;
		}

		List<String> list = new ArrayList<>();
		for (String url : ENDPOINTS) {
			list.add(url);
		}
		for (String url : oauthUrls) {
			list.add(url);
		}

		return list.toArray(new String[list.size()]);
	}

	public void setOauthUrls(String[] oauth_urls) {
		this.oauthUrls = oauth_urls;
	}

}
